import { defineStore } from 'pinia'
import { getUserInfoApi } from '@/api/login'

interface UserInfo {
  avatar: string
  nickname: string
  signature: string
}

const useStore = defineStore('user', {
  state: () => ({
    userInfo: {
      avatar: '',
      nickname: '',
      signature: '',
    } as UserInfo,
    token: '',
  }),
  actions: {
    setUserInfo(info: Partial<UserInfo>) {
      this.userInfo = { ...this.userInfo, ...info }
    },
    setToken(token: string) {
      this.token = token
    },
  },
  getters: {
    getUserInfo: state => state.userInfo,
  },
})

export const withOutUserStore = () => useStore()

export default useStore
